package com.example.shop_2302.search

import androidx.lifecycle.viewModelScope
import com.example.base.entity.GoodsEntity
import com.example.base.entity.Res
import com.example.base.mvvm.BaseViewModel
import com.example.shop_2302.utils.SingleLiveData
import kotlinx.coroutines.launch

class SearchViewModel:BaseViewModel() {
    //返回值--搜索
    val searchSuccess = SingleLiveData<Res<GoodsEntity>>()
    val searchFail = SingleLiveData<String>()

    fun search(keyword:String,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                searchSuccess.postValue(apiServer.search(keyword, limit, page))
            }catch (e:Exception){
                searchFail.postValue(e.message.toString())
            }
        }
    }
}